/**
 * 
 */
package com.zoiz.util;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author Administrator
 * 
 */
public class PageBean {
	Map<String, String> cs = new HashMap<String, String>();
	Integer currentPage = -1;// 当前页

	public Integer totalPage = 0;// 总页数

	Integer rowsPerPage = 10;// 每页10条数据

	Integer totalRows = 0;// 总数据数

	Integer pageStartRow = 0;// 每页的起始数

	Integer pageEndRow = 0;// 每页显示数据的终止数

	boolean hasNextPage = false; // 是否有下一页

	boolean hasPreviousPage = false; // 是否有前一页

	String action = "";
	
	List model = new ArrayList();

	public PageBean() {
	}

	public PageBean(Integer currentPage, Integer rowsPerPage, Integer totalRows) {
		this.rowsPerPage = rowsPerPage;
		this.totalRows = totalRows;
		hasPreviousPage = false;
		this.currentPage = currentPage != null ? currentPage : 1;
		if ((totalRows % rowsPerPage) == 0) {
			totalPage = totalRows / rowsPerPage;
		} else {
			totalPage = totalRows / rowsPerPage + 1;
		}

		if (currentPage >= totalPage) {
			hasNextPage = false;
		} else {
			hasNextPage = true;
		}

		if (currentPage > 1) {
			this.hasPreviousPage = true;
		}
		if (totalRows < rowsPerPage) {
			this.pageStartRow = 0;
			this.pageEndRow = totalRows;
		} else {
			this.pageStartRow = 0;
			this.pageEndRow = rowsPerPage;
		}

	}

	public int getStartRow(){
		return (currentPage-1)*rowsPerPage;
	}
	public Integer getCurrentPage() {
		return currentPage;
	}

	public void setCurrentPage(Integer currentPage) {
		this.currentPage = currentPage;
	}

	public Integer getRowsPerPage() {
		return rowsPerPage;
	}

	public void setRowsPerPage(Integer rowsPerPage) {
		this.rowsPerPage = rowsPerPage;
	}

	public Map<String, String> getCs() {
		return cs;
	}

	public void addCtion(String key, String value) {
		cs.put(key, value);
	}

	public Integer getTotalPage() {
		return totalPage;
	}

	public void setTotalPage(Integer totalPage) {
		this.totalPage = totalPage;
	}

	public Integer getTotalRows() {
		return totalRows;
	}

	public void setTotalRows(Integer totalRows) {
		this.totalRows = totalRows;
	}

	public boolean isHasNextPage() {
		return hasNextPage;
	}

	public void setHasNextPage(boolean hasNextPage) {
		this.hasNextPage = hasNextPage;
	}

	public boolean isHasPreviousPage() {
		return hasPreviousPage;
	}

	public void setHasPreviousPage(boolean hasPreviousPage) {
		this.hasPreviousPage = hasPreviousPage;
	}

	public String getAction() {
		return action;
	}

	public void setAction(String action) {
		this.action = action;
	}

	public int[] getPageNo(){
		int a = currentPage;
		int tp = totalPage;
		int[] r = new int[10];
		int idx = 0;
		for (int i = 3; i > 0; i--) {
			if (a - i > 0 && a-i!=1) {
				r[idx] = a - i;
				idx++;
			} else {
				continue;
			}
		}
		if(a!=1 && a!=totalPage){
			r[idx] = a;
			idx++;
		}
		int tmp = 10 - idx;
		for (int i = 1; i <= tmp; i++) {
			if (a + i < (r[0] + 10) && a + i < tp) {
				r[idx] = a + i;
				idx++;
			} else {
				continue;
			}
		}
		r = Arrays.copyOf(r, idx);
		return r.length==0?null:r;
	}

	public List getModel() {
		return model;
	}

	public void setModel(List model) {
		this.model = model;
	}
}
